package org.electronic.registration.bo;

import javax.persistence.*;
import java.io.Serializable;

/**
 * User: Egor
 * Date: 10.11.11
 */
@Entity(name = "Arm.Doctor")
@Table(name = "Arm.Doctor")
@NamedQueries({
        @NamedQuery(name = Doctor.GET_ALL_DOCTORS, query = "select d from Arm.Doctor d"),
        @NamedQuery(name = Doctor.GET_DOCTOR_BY_NAME, query = "select d from Arm.Doctor d where d.fullName like ?")
})
public class Doctor implements Serializable {

    public static final String GET_ALL_DOCTORS = "GET_ALL_DOCTORS";
    public static final String GET_DOCTOR_BY_NAME = "GET_DOCTOR_BY_NAME";

    @Id
    @GeneratedValue
    private Integer id;

    private String fullName;

    private String departament;

    private Integer roomNumber;

    @OneToOne(targetEntity = Doctor.class)
    @JoinColumn(name = "forwardTo")
    private Doctor forwardTo;

    private String specialization;


    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getSpecialization() {
        return specialization;
    }

    public void setSpecialization(String specialization) {
        this.specialization = specialization;
    }

    public Departament getDepartament() {
        return Departament.fromString(departament);
    }

    public void setDepartament(Departament departament) {
        this.departament = departament.toString();
    }

    public String getFullName() {
        return fullName;
    }

    public void setFullName(String fullName) {
        this.fullName = fullName;
    }

    public Doctor getForwardTo() {
        return forwardTo;
    }

    public void setForwardTo(Doctor forwardTo) {
        this.forwardTo = forwardTo;
    }

    public Integer getRoomNumber() {
        return roomNumber;
    }

    public void setRoomNumber(Integer roomNumber) {
        this.roomNumber = roomNumber;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Doctor doctor = (Doctor) o;

        if (departament != null ? !departament.equals(doctor.departament) : doctor.departament != null) return false;
        if (!fullName.equals(doctor.fullName)) return false;
        if (!id.equals(doctor.id)) return false;
        if (specialization != null ? !specialization.equals(doctor.specialization) : doctor.specialization != null)
            return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id.hashCode();
        result = 31 * result + fullName.hashCode();
        result = 31 * result + (departament != null ? departament.hashCode() : 0);
        result = 31 * result + (specialization != null ? specialization.hashCode() : 0);
        return result;
    }


}
